package com.example.service;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

import com.example.downloaddemo.DownloadThread;

import android.app.Service;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Binder;
import android.os.IBinder;
import android.util.Log;

/**
 * 下载服务类
 */
public class DownloadService extends Service {

	private static final String DOWNLOADURL = "http://api.zhuandiane.com/download/guanwang";
	private static final String TAG = "ZL";
	private DownloadBinder mBinder = new DownloadBinder();

	@Override
	public void onCreate() {
		super.onCreate();
		Log.i(TAG, "Service onCreate");
	}

	@Override
	public IBinder onBind(Intent intent) {
		Log.i(TAG, "Service onBind");
		return mBinder;
	}

	@Override
	public void unbindService(ServiceConnection conn) {
		super.unbindService(conn);
		Log.i(TAG, "Service unbindService");
	}

	@Override
	public boolean onUnbind(Intent intent) {
		Log.i(TAG, "Service onUnbind");
		return super.onUnbind(intent);
	}

	@Override
	public void onDestroy() {
		super.onDestroy();
		Log.i(TAG, "Service onDestroy");
	}

	/**
	 * 开始下载
	 */
	public void startDownload() {
		Log.i(TAG, "start download");
		new DownloadThread(DOWNLOADURL).start();
	}

	/**
	 * 停止下载
	 */
	public void stopDownload() {
		Log.i(TAG, "stop download");
	}

	/**
	 * 获取下载进度
	 */
	public void getProgress() {
		Log.i(TAG, "get progress");
	}

	/**
	 * Service接口访问类
	 */
	public class DownloadBinder extends Binder {

		public DownloadService getService() {
			Log.i(TAG, "DownloadBinder getService");
			return DownloadService.this;
		}

	}

}
